import 'package:flutter/material.dart';

class CounterSetStatePage extends StatefulWidget {
  const CounterSetStatePage({super.key});

  @override
  State<CounterSetStatePage> createState() => _CounterSetStatePageState();
}

class _CounterSetStatePageState extends State<CounterSetStatePage> {
  int count = 0;

  void increment() {
    setState(() {
      count++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('setState 状态管理'),
        leading: IconButton(
          icon: const Icon(Icons.home),
          onPressed: () => Navigator.of(context)
              .pushNamedAndRemoveUntil('/', (route) => false),
        ),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text('count: $count', style: const TextStyle(fontSize: 24)),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: increment,
              child: const Text('count+1'),
            ),
          ],
        ),
      ),
    );
  }
}
